/*
* Authors: Savenko Maria
*           ***
*           ***
*/


#define BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS
#include "stdafx.h"

#include "ramsey_algorithm.h"
#include "polynomial_algorithm.h"
#include "kclaw_Free_Graphs.h"

#include <string>
#include <iostream>
#include <fstream>
#include <time.h>



void assign_names_to_verteces(graph_t & g) {

    graph_traits<graph_t>::vertex_iterator i, iend;

    ostringstream strStream;
	for(tie(i, iend) = vertices(g); i != iend; ++i) {
		strStream.str("");
        strStream << "v" << *i;
        g[*i].name = strStream.str();
	}
}


bool read_graph(graph_t & graph){
	// Construct an empty graph and prepare the dynamic_property_maps.
	dynamic_properties dp(&boost::ignore_other_properties);
    
    std::string fname;
    cout << "Enter file name ";
    cin >> fname;
	
    std::ifstream ifile;
	ifile.open(fname.c_str());

    if ( ! ifile ) {
      cerr << "Error: can't open file " << ifile << endl;
      return false;
    }

    bool status = read_graphviz(ifile,graph,dp,"node_id");

    ifile.close();

    if ( status ) {
        cout << "File successfully read. " << endl;
    } else {
        cout << "File reading failed. "<< endl;
        return false;
    }

    assign_names_to_verteces(graph);

	return true;
}


void _tmain(int argc, _TCHAR* argv[])
{	
	char input;
    clock_t start, end;
    graph_t graph(0);
	cout << "Choose from the following (for exit - anything else):" << endl;
	cout << "1 - To run Ramsey algorithm" << endl;
    cout << "2 - To run algorithm using Continuous Multivariable Polynomial formulations" << endl;
	cout << "3 - To find r-locally optimal independent set of k-claw free graph" << endl;

	cin >> input;

    switch (input) {
	case '1':
		{
            if (!read_graph(graph))
                break;

			ramsey_algorithm solver(graph);
			
            start = clock();
            solver.clique_removal();
            end = clock();
            solver.print_independent_set();

            break;
		}
    case '2':
		{
            if (!read_graph(graph))
                break;

			polynomial_algorithm solver(graph);
			
            start = clock();
            solver.run();
            end = clock();
            solver.print_independent_set();

            break;
		}
	case '3':
		{
			if(!read_graph(graph))
				break;
			unsigned r,k;
			cout << "r =";
			cin >>r;
			cout <<"k =";
			cin >>k;
			kclaw_Free_Graphs solver(graph,r,k);

			start = clock();
			solver.run();
			end = clock();
			solver.print_independent_set();

			break;
		}
	default:
		cout << "Exiting..." << endl;
        exit(1);
	}
    
    cout << endl;
    cout << "Time Costed: " << (double)(end - start) / CLOCKS_PER_SEC << endl;
	cin.get();
}
